<?php
$domain=$_SERVER['HTTP_HOST'];
$agency=new Model('user_agency');
$agency->find(array('domain'=>$domain));
$register_check=$agency->register_check;

if(Request::post()){
    $user = new Model('user');
    $phonenumber = Request::post('phonenumber');
    $code = Cache::get('sms_code');
    $yzm = Request::post('code');
    $pwd = Request::post('pwd');
    $counts=db_query("select * from qvmh_user where un=$phonenumber");
    if(!$counts){
        echo '<script type="text/javascript">alert("您还未注册!请先注册");history.go(-1);</script>';
        exit;
    }elseif($register_check==1&&($yzm==null||$yzm!=$code)){
        echo '<script type="text/javascript">alert("验证码错误!请输入正确的验证码");history.go(-1);</script>';
        exit;
    }elseif(!empty($phonenumber)&&!empty($yzm)&&!empty($pwd)){
        $upd = $user->update(['id'=>$counts[0]["id"]],['pwd'=>md5($pwd)]); 
        if($upd){
            echo '<script type="text/javascript">alert("修改成功，请登录");</script>';
            Redirect::delay_to('/login',3);
        }else{
            echo '<script type="text/javascript">alert("修改失败");history.go(-1);</script>';
            exit;
        }
    }
}
